package hc.j2me.ui;

import hc.core.ConditionWatcher;
import hc.core.ContextManager;
import hc.core.EventCenter;
import hc.core.HCTimer;
import hc.core.IEventHCListener;
import hc.core.IScreenClient;
import hc.core.IWatcher;
import hc.core.Message;
import hc.core.MsgBuilder;
import hc.core.data.DataInputEvent;
import hc.core.util.BackendMsgListener;
import hc.core.util.HCURL;
import hc.j2me.Main;
import hc.j2me.ScreenClientManager;
import hc.j2me.Starter;
import hc.j2me.util.ImageUtility;
import hc.j2me.util.Jcip;
import hc.j2me.util.ScreenUtil;

import java.io.IOException;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.game.LayerManager;
import javax.microedition.lcdui.game.Sprite;

public class HCCtrlGameCanvas extends PNGGameCanvas implements IScreenClient, BackendMsgListener {
	private final int _80;
	private final int _32;
	private final int _48;
	private final int _64;
	private final int _83;
	private final int RIGHT_SOFT_KEY = -7;
	private final int LEFT_SOFT_KEY = -6;
	private final int C_BACK_SOFT_KEY = -8;

	private Sprite sp_tb_exit, sp_tb_services, sp_tb_mouse, sp_tb_about,
			sp_tb_screen, sp_tb_config;
	private final Sprite userSelectedMenu;
	private Sprite sp_tr_toolmenu, sp_tr_points, sp_tr_points_user;
	private PosMVC posMVC;
	public Sprite sp_mouseMove_cursor;
	private Sprite[] mouseOpLists;
	private Sprite[] mouseOpUserLists = {};
	private short mouseOpUserListNum;//存储实际用户自定义的图标数量
	private Sprite sp_tr_Screen, sp_screen_focus, sp_tr_Mouse, sp_mouse_focus,
			sp_mouse_splide, sp_tr_About, sp_tr_About_logo;

	private final short ICON_EXIT_IDX = 0, ICON_EXPAND_IDX = 1,
			ICON_SCREEN_IDX = 2, ICON_MOUSE_IDX = 3, ICON_ABOUT_IDX = 5,
			ICON_CFG_IDX = 4;

	private final short MODE_MENU = 0;
	private final short MODE_SCREEN = 1;
	private final short MODE_ABOUT = 2;
	private final short MODE_MOUSE = 3;

	// 菜单条初始选中
	private int indexSelectedMenuItem = 0;
	private short curr_menu_mode = MODE_MENU;
	private final int TOTAL_MENU_ITEM_NUM = 6;
	private final int MENU_ITEM_NEVEN_HIDE_NUM = 2;

	private boolean isShowABCIcon = true;

	private TextBox dispRemoteTxtBox;

	SpriteMover screenMover, mouseMover, userOpMover;
	
	public HCCtrlGameCanvas() {
		super(200);// suppressKeyEvents

		setScreenID(HCURL.REMOTE_HOME_SCREEN);
		
		_32 = _16 * 2;
		_48 = _16 * 3;
		_64 = _16 * 4;
		_83 = _16 * 5 + 3;
		_80 = _16 * 5;

		y_menu = ScreenClientManager.getClientHeight() - _16 - 2 * userMouseSplitWidth;
		y_menu_item = y_menu + userMouseSplitWidth;

		Image selImage = null;
		try {
			selImage = Image.createImage("/hc/j2me/res/select_" + _16 + ".png");
		} catch (IOException e1) {
		}
		if(selImage != null){
			userSelectedMenu = new Sprite(selImage);
		}else{
			userSelectedMenu = new Sprite(createSelectedBox(
					_16, _16,
					ImageUtility.GREEN));
		}
		
		final HCCtrlGameCanvas self = this;

		ScreenUtil.middleX = ((short) (ScreenClientManager.getClientWidth() / 2));
		ScreenUtil.middleY = ((short) (ScreenClientManager.getClientHeight() / 2));

		buildToolbar();

		try {
			sp_mouseMove_cursor = new Sprite(
					Image.createImage("/hc/j2me/res/mouse_move_16.png"));
			sp_mouseMove_cursor.setPosition(ScreenUtil.middleX,
					ScreenUtil.middleY);
			lm.append(sp_mouseMove_cursor);
		} catch (Exception e) {

		}
		lm.append(screenSprite);

		try {
			String[] url = {
					"/hc/j2me/res/abc_" + _16 + ".png",// sp_tbp_point_abc
					"/hc/j2me/res/ab_selected_" + _16 + ".png",// sp_tbp_txt_select
					"/hc/j2me/res/bksp_" + _16 + ".png",// sp_tbp_backspace
					"/hc/j2me/res/ab_2_mobile_" + _16 + ".png",// sp_tbp_copyTxtToMobile
					"/hc/j2me/res/mouse_rt_clk_" + _16 + ".png",// sp_tbp_mouse_right
					"/hc/j2me/res/m_mv_" + _16 + ".png"};
			String[] modeurl = {
					null,
					"/hc/j2me/res/ab_selected_o_" + _16 + ".png",// sp_tbp_txt_select
					null,
					null,
					"/hc/j2me/res/mouse_rt_clk_o_" + _16 + ".png",// sp_tbp_mouse_right
					"/hc/j2me/res/m_mv_o_" + _16 + ".png"};

			sp_tr_points = buildBackMouse(url.length,
					userMouseWidthIdx, userMouseHeightIdx);
			
			final int screenIdx = PNGGameCanvas.getLayerIdx(lm, screenSprite);
			
			lm.insert(sp_tr_points, screenIdx);

			mouseOpLists = new Sprite[url.length];
			int tmpUserMouseHeightIdx = userMouseHeightIdx + userMouseSplitWidth;
			for (int i = 0; i < url.length; i++) {
				Sprite tmp;
				if(modeurl[i] == null){
					tmp = new Sprite(Image.createImage(url[i]));
				}else{
					tmp = new ModeSprite(Image.createImage(url[i]), Image.createImage(modeurl[i]));
				}
				tmp.setPosition(userMouseWidthIdx + userMouseSplitWidth,
						tmpUserMouseHeightIdx);
				lm.insert(tmp, screenIdx);

				mouseOpLists[i] = tmp;

				tmpUserMouseHeightIdx += _blockWidth;
			}
			
			Object[] sps = {sp_tr_points, mouseOpLists, null, null};//后面两个null为动态用户定义保留
			SpritesLoc spLoc = new SpritesLoc(sps, LOCK, this);
			spLoc.isMoveIn = false;
			spLoc.moveX = ScreenClientManager.getClientWidth() - (userMouseWidthIdx - _blockWidth);
			
			userOpMover = new SpriteMover();
			userOpMover.spriteloc = spLoc;
			
			final IWatcher userOpIcon = new IWatcher() {
				final HCCtrlGameCanvas gameCanvas = self;
				
				public boolean watch() {
					if(userOpMover.isAddWatch()){
						//正在移动时，暂停放入
						return false;
					}
					
					synchronized (LOCK) {
						if(sp_tr_points_user != null){
							//移出旧的
							for (int i = 0; i < mouseOpUserListNum; i++) {
								lm.remove(mouseOpUserLists[i]);
							}
							userOpMover.spriteloc.removeSprite(mouseOpUserLists);
						}
						Jcip j = new Jcip(jcip);
						Image[] userMouseIcon = j.getArrImage();
						
						if (userMouseIcon.length > 0) {
							Sprite[] tmpSps = new Sprite[TOTAL_MENU_ITEM_NUM];
							if(sp_tr_points_user == null){
								sp_tr_points_user = buildBackMouse(TOTAL_MENU_ITEM_NUM,
										userMouseWidthIdx - _blockWidth, userMouseHeightIdx);
								final int screenIdx = PNGGameCanvas.getLayerIdx(lm, screenSprite);
								lm.insert(sp_tr_points_user, screenIdx);
								userOpMover.spriteloc.addSprite(sp_tr_points_user);
							}
							
							final int userOpIdx = PNGGameCanvas.getLayerIdx(lm, sp_tr_points_user);
		
							int tmpUserMouseHeightIdx = userMouseHeightIdx + userMouseSplitWidth;
							
							mouseOpUserListNum = (short)userMouseIcon.length;
							for (int k = 0; k < userMouseIcon.length; k++) {
								Image image = userMouseIcon[k];
								if(image.getWidth() != _16){
									image = ImageUtility.scaleImage(image, _16, _16);
								}
								Sprite tmp = new Sprite(image);
								tmp.setPosition(userMouseWidthIdx + userMouseSplitWidth - _blockWidth,
										tmpUserMouseHeightIdx);
								lm.insert(tmp, userOpIdx);
								tmpSps[k] = tmp;
								tmpUserMouseHeightIdx += _blockWidth;
							}
		
							mouseOpUserLists = tmpSps;
							userOpMover.spriteloc.addSprite(mouseOpUserLists);
							
							sp_tr_points_user.setVisible(isShowABCIcon);
							for (int i = 0; i < mouseOpUserListNum; i++) {
								mouseOpUserLists[i].setVisible(isShowABCIcon);
							}
							
							if(isShowABCIcon){
								gameCanvas.refreshScreenDirect();
							}
						}
					}

					return true;
				}
				
				public void setPara(Object p) {
					jcip = (String)p;
				}
				String jcip;
				public boolean isNotCancelable() {
					return false;
				}
				
				public void cancel() {
				}
			};
			
			//以下段依赖于上行图层所在位置，所以要置于后
			EventCenter.addListener(new IEventHCListener() {
				IWatcher watch = userOpIcon;
				public byte getEventTag() {
					return MsgBuilder.E_SCREEN_EXT_MOUSE_ICON;
				}
				public boolean action(final byte[] bs) {
					final String jcip = Message.getMsgBody(bs, MsgBuilder.INDEX_MSG_DATA);
					watch.setPara(jcip);
					ConditionWatcher.addWatcher(watch);
					return true;
				}
			});
			
			userOpMover.flipMove();

		} catch (IOException e) {
			e.printStackTrace();
		}

		refreshScreenDirect();

		// Image image = null;
		// try { image = Image.createImage("/hc/j2me/res/images.png"); }
		// catch (IOException ioe) {}
		// TiledLayer tiledLayer = new TiledLayer(1, 1, image, 256, 192);
		//
		// lm.append(tiledLayer);

//		保留为以后使用的接口和逻辑
//		MsgNotifier.getInstance().setCurrListener(this);

		shortPanel = new HCPressShortPanel(this, lm, sp_mouseMove_cursor, _blockWidth, userMouseSplitWidth, _16);

	}
	
	protected void keyPressed(int keyCode) {

		int gameAction = getGameAction(keyCode);
		//L.V = L.O ? false : LogManager.log("KeyCode:" + keyCode + ", GameAction:" + gameAction);

		actionKey(keyCode, gameAction);
	}

	private void actionKey(int keyCode, int gameAction) {
		if (isShowABCIcon) {
			// 键盘焦点与触屏焦点要切换
			userSelectedMenu.setVisible(true);
			userSelectedMenu.setPosition(_blockWidth
					* indexSelectedMenuItem + userMouseSplitWidth, y_menu_item);
		}

		int done = R_CANCEL;
		if (curr_menu_mode == MODE_MENU) {
			done = actionMenu(keyCode, gameAction);
		} else if (curr_menu_mode == MODE_MOUSE) {
			done = actionMouse(keyCode, gameAction);
		} else if (curr_menu_mode == MODE_ABOUT) {
			done = actionAbout(keyCode, gameAction);
		} else if (curr_menu_mode == MODE_SCREEN) {
			done = actionScreen(keyCode, gameAction);
		}
		
//		强制显示主按钮区
//		if (isShowABCIcon) {
//			showMouseOp(false);
//			if (done != R_OK) {
//				refreshScreenDirect();
//			}
//		}

		responseActionSound(done, true);
	}

	public void showMouseOp(final boolean visiable) {
//		for (int i = 0; i < mouseOpLists.length; i++) {
//			mouseOpLists[i].setVisible(visiable);
//		}
//		for (int i = 0; i < mouseOpUserListNum; i++) {
//			mouseOpUserLists[i].setVisible(visiable);
//		}
//
//		sp_tr_points.setVisible(visiable);
//		if (sp_tr_points_user != null) {
//			sp_tr_points_user.setVisible(visiable);
//		}
		if(isShowABCIcon != visiable){
			userOpMover.flipMove();
		}
		isShowABCIcon = visiable;
	}

	protected void keyRepeated(int keyCode) {
		int gameAction = getGameAction(keyCode);
		// System.out.println("Repeat:" + keyCode);

		if (gameAction == UP || gameAction == DOWN || gameAction == LEFT
				|| gameAction == RIGHT || gameAction == FIRE 
				|| keyCode == KEY_NUM2 || keyCode == KEY_NUM4 
				|| keyCode == KEY_NUM6 || keyCode == KEY_NUM8) {
			short count = 3;
			for (short j = 0; j < count; j++) {
				actionKey(keyCode, gameAction);
			}
		}
	}

	private int visiable_icon_num = 0;
	private final int y_menu, y_menu_item;

	private void buildToolbar() {
		// Sprite exit = new Sprite(ImageUtility.createStringImage("Exit"));
		// exit.setPosition(0,ScreenClientManager.getClientHeight() - _16);
		boolean isHideToolbar = Starter.config.isHideToolbar;

		try {
			
			sp_tb_exit = new Sprite(
					Image.createImage("/hc/j2me/res/exit_" + _16 + ".png"));
			sp_tb_exit.setPosition((visiable_icon_num++)
					* _blockWidth + userMouseSplitWidth, y_menu_item);
			lm.append(sp_tb_exit);

			String serviceHideIcon = null;
			if (isHideToolbar) {
				serviceHideIcon = "/hc/j2me/res/rightarrow_" + _16 + ".png";
			} else {
				serviceHideIcon = "/hc/j2me/res/leftarrow_" + _16 + ".png";
			}
			sp_tb_services = new Sprite(Image.createImage(serviceHideIcon));
			sp_tb_services.setPosition((visiable_icon_num++)
					* _blockWidth + userMouseSplitWidth, y_menu_item);
			lm.append(sp_tb_services);

			sp_tb_screen = new Sprite(
					Image.createImage("/hc/j2me/res/screen_" + _16 + ".png"));
			sp_tb_screen.setPosition((visiable_icon_num++)
					* _blockWidth + userMouseSplitWidth, y_menu_item);
			lm.append(sp_tb_screen);
			if (isHideToolbar) {
				sp_tb_screen.setVisible(false);
			}

			sp_tb_mouse = new Sprite(
					Image.createImage("/hc/j2me/res/mouse_" + _16 + ".png"));
			sp_tb_mouse.setPosition((visiable_icon_num++)
					* _blockWidth + userMouseSplitWidth, y_menu_item);
			lm.append(sp_tb_mouse);
			if (isHideToolbar) {
				sp_tb_mouse.setVisible(false);
			}

			sp_tb_config = new Sprite(
					Image.createImage("/hc/j2me/res/config_" + _16 + ".png"));
			sp_tb_config.setPosition((visiable_icon_num++)
					* _blockWidth + userMouseSplitWidth, y_menu_item);
			lm.append(sp_tb_config);
			if (isHideToolbar) {
				sp_tb_config.setVisible(false);
			}

			sp_tb_about = new Sprite(
					Image.createImage("/hc/j2me/res/comment_" + _16 + ".png"));
			sp_tb_about.setPosition((visiable_icon_num++)
					* _blockWidth + userMouseSplitWidth, y_menu_item);
			lm.append(sp_tb_about);
			if (isHideToolbar) {
				sp_tb_about.setVisible(false);
			}

			// 建背景透明层
			int fullToolWidth = TOTAL_MENU_ITEM_NUM * _blockWidth;
			sp_tr_toolmenu = new Sprite(createTransforImage(fullToolWidth, _blockWidth,
					ImageUtility.COLOR_TRANS_LAY));
			if (isHideToolbar) {
				sp_tr_toolmenu.setPosition(-fullToolWidth
						+ (MENU_ITEM_NEVEN_HIDE_NUM * _blockWidth),
						y_menu);
				visiable_icon_num = MENU_ITEM_NEVEN_HIDE_NUM;
			} else {
				sp_tr_toolmenu.setPosition(0, y_menu);
			}

			lm.append(sp_tr_toolmenu);

			userSelectedMenu.setPosition(userMouseSplitWidth, y_menu_item);
			lm.insert(userSelectedMenu, 0);//置于最上
		} catch (Exception e) {

		}
	}

	public void pointerPressed(final int x, final int y) {
//		L.V = L.O ? false : LogManager.log("Pressed x:" + x + ", y:" + y);
		actionPointerPressed(x, y);
		
		pointDragRemoteStartX = locX + x;
		pointDragRemoteStartY = locY + y;

		
		//以下代码是键盘切换到触控时，激发，现在缺省为显示。
//		if (isShowABCIcon == false) {
//			showMouseOp(true);
//		}
		// System.out.println("Point click : x=" + x + ", y=" + y);

	}

	/**
	 * 对于MIDP 2.0的手机，不一定都支持半透明效果的 Alpha
	 * Processing时取决于机型Display.numAlphaLevels()方法的值 如果该值为2那就只能支持全透明或者不透明."
	 * @param alpha 
	 * @return immutable Image 
	 */
	public Image createTransforImage(int width, int height, int alpha) {
		int[] array;
		array = new int[width * height];
		ImageUtility.initBoxAtCell(width, height, alpha, array, _blockWidth, userMouseSplitWidth, _16);
		return ImageUtility.createSafeAlphaImg(array, width, height, array.length, ImageUtility.isHardAlpha);
	}

	private Sprite buildBackMouse(int len, int x, int y) {
		Sprite sp_tr_points_tmp = new Sprite(createTransforImage(_blockWidth, _blockWidth * len,
				ImageUtility.COLOR_TRANS_LAY));
		sp_tr_points_tmp.setPosition(x, y);
		return sp_tr_points_tmp;
	}

	private int pointLastReleaseX, pointLastReleaseY;
	private long pointDoubleClickLastTime = System.currentTimeMillis();

	public void pointerReleased(final int x, final int y) {
		if(actionPointerReleased(x, y) == R_OK){
			return;
		}
		
//		L.V = L.O ? false : LogManager.log("Point released : x=" + x + ", y=" + y);
		if(posMVC != null && posMVC.isOnMode()){
			final int r;
			if(isDragged){
				r = posMVC.pointerDragged(pointDragRemoteStartX,
						pointDragRemoteStartY, locX + x,
						locY + y, x, y);
				resetDragTag();
			}else{
				r = posMVC.pointerReleased(x, y);
			}
			responseActionSound(r, false);
			return;
		}
		
		if (curr_menu_mode == MODE_ABOUT) {
			// 特例，关闭about小窗口
			actionAbout(KEY_NUM0, 0);
			responseActionSound(1, true);
			return;
		}

		final long currMS = System.currentTimeMillis();
		if (pointLastReleaseX >= (x-3) && pointLastReleaseX <= (x+3) 
				&& pointLastReleaseY >= (y-3)&& pointLastReleaseY <= (y+3)) {
//			L.V = L.O ? false : LogManager.log("TimeDiff:" + (currMS - pointDoubleClickLastTime));
			if ((currMS - pointDoubleClickLastTime) < 1000) {
				// 触屏双击事件
				int r = actionPointDouble(x, y);
				if (r != 0) {
					responseActionSound(r, true);
				}
				pointDoubleClickLastTime = currMS;
				return;
			}
		}
		pointDoubleClickLastTime = currMS;
		pointLastReleaseX = x;
		pointLastReleaseY = y;
//		L.V = L.O ? false : LogManager.log("IsDragged:" + isDragged);
		if (isDragged) {
			final int toX = locX + x;
			final int toY = locY + y;

			//自动移块
//			dragStopDelayTimer.releaseDrag();

			if(toX >= (pointDragRemoteStartX-1) && toX <= (pointDragRemoteStartX+1)
					&& toY >= (pointDragRemoteStartY-1) && toY <= (pointDragRemoteStartY+1)){
				resetDragTag();

			}else{
				int r = actionPointDrag(pointDragRemoteStartX,
						pointDragRemoteStartY, toX,
						toY, x, y);
				if (r != 0) {
					
					responseActionSound(r, true);
				}

				resetDragTag();

				return;
			}
		}
		
		int r = actionPointSingClick(x, y);
		if (r != 0) {
			responseActionSound(r, true);
		}
	}
	
	/**
	 * 各坐标为远程服务器的绝对坐标，此方法参数有别于其它
	 * 
	 * @param startX
	 * @param startY
	 * @param endX
	 * @param endY
	 * @return
	 */
	private short actionPointDrag(final int startX, final int startY, 
			final int endX, final int endY, final int x, final int y) {
//		L.V = L.O ? false : LogManager.log("Point Drag from[" + startX + ", " + startY +
//		 "] to [" + endX + ", " + endY + "]");
		short out = -1;
		if (isTextSelectedBegin) {
			if(posMVC == null){
				posMVC = new PosMVC(this, lm, sp_mouseMove_cursor, userSelectedMenu,_16, _blockWidth, userMouseSplitWidth, ImageUtility.upSideColor, ImageUtility.downSideColor, ImageUtility.COLOR_TRANS_LAY);
			}
			posMVC.setInitPos(startX, startY, x - (endX - startX), y - (endY - startY), x, y);
			
			out = 1;
		} else {
			if(isAutoDraged == false){
				boolean moved = ScreenClientManager.moveUp(endY - startY);
				moved = (ScreenClientManager.moveRight(startX - endX) || moved);
				if(moved){
					if(screenMover != null && (screenMover.isAddWatch() == false)){
						refreshScreenFocus();
					}
				}
				out = moved ? (short) 1 : (-1);
			}
		}
		return out;
	}

	// 本屏的绝对坐标
	// private int pointDragStartX, pointDragStartY;

	// 为远程服务器的绝对坐标
	private int pointDragRemoteStartX, pointDragRemoteStartY;

	public void setAutoDragedRemote(){
		isAutoDraged = true;
	}
	
	private boolean checkInMenu(int x, int y){
		if (y > (ScreenClientManager.getClientHeight() - _blockWidth)) {
			// 检查是否点击主菜单条
			if (x < (visiable_icon_num * _blockWidth)) {
				//
				return true;
			}
		}
		return false;
	}

	private short actionPointSingClick(int x, int y) {
//		 L.V = L.O ? false : LogManager.log("Point sing click at [" + x + ", " + y + "]");

		if(checkInMenu(x, y)){
			int tryMenuItem = (x / _blockWidth);

			indexSelectedMenuItem = tryMenuItem;
			userSelectedMenu.setVisible(true);
			userSelectedMenu.setPosition(_blockWidth
					* (indexSelectedMenuItem) + userMouseSplitWidth, y_menu_item);

			// 先 关闭以前打开的
			if (curr_menu_mode != MODE_MENU) {
				if (curr_menu_mode == MODE_MOUSE) {
					actionMouse(KEY_NUM0, 0);
					if (indexSelectedMenuItem == ICON_MOUSE_IDX){
						return 1;
					}
				} else if (curr_menu_mode == MODE_ABOUT) {
					actionAbout(KEY_NUM0, 0);
					if (indexSelectedMenuItem == ICON_ABOUT_IDX) {
						return 1;
					}
				} else if (curr_menu_mode == MODE_SCREEN) {
					actionScreen(KEY_NUM0, 0);
					if (indexSelectedMenuItem == ICON_SCREEN_IDX) {
						return 1;
					}
				}
			}

			return actionMenu(KEY_NUM5, FIRE);
		}

		// 点击仿真屏幕
		if (curr_menu_mode == MODE_SCREEN) {
			if (x > V_X && x < (V_X + Virtual_W) && y > V_Y
					&& y < (V_Y + Virtual_H)) {
				int half_vw = sp_screen_focus.getWidth() / 2;
				int half_vh = sp_screen_focus.getHeight() / 2;

				// 计算仿真框的中心点到x,y
				if (x + half_vw > (V_X + Virtual_W)) {
					x = V_X + Virtual_W - half_vw;
				} else if (x - half_vw < V_X) {
					x = V_X + half_vw;
				}
				if (y + half_vh > (V_Y + Virtual_H)) {
					y = V_Y + Virtual_H - half_vh;
				} else if (y - half_vh < V_Y) {
					y = V_Y + half_vh;
				}

				// 将中心点x,y转换到左上角
				x -= half_vw;
				y -= half_vh;
				sp_screen_focus.setPosition(x, y);

				virtualMoveLocX = (x - V_X)
						* ScreenClientManager.remote_screen_width / Virtual_W;
				virtualMoveLocY = (y - V_Y)
						* ScreenClientManager.remote_screen_height / Virtual_H;

				actionScreen(KEY_NUM5, 0);
				return R_OK;
			}
			
			//点击[ESC:0]
			final short pointOnEsc = pointOnEsc(x, y, sp_tr_Screen);
			if(pointOnEsc != R_CONTINUE){
				return pointOnEsc;
			}
		}

		// 使用仿真鼠标
		if (curr_menu_mode == MODE_MOUSE) {
			// sp_mouse_focus.setPosition(48, M_Y + M_FIRST_ICON_Y

			if ((y > (M_Y + M_FIRST_ICON_Y) && y < (M_Y + M_FIRST_ICON_Y + _16))) {
				if ((x > _48 && x < _48 + _16)) {
					// 第一排中间
					return actionMouse(KEY_NUM2, 0);
				} else if (x > (_48 - _32) && x < (_48 - _16)) {
					// 第一排左
					return actionMouse(KEY_NUM1, 0);
				} else if (x > (_48 + _32) && x < _48 + _48) {
					// 第一排右
					return actionMouse(KEY_NUM3, 0);
				}
			}
			if ((y > (M_Y + M_SECOND_ICON_Y) && y < (M_Y + M_SECOND_ICON_Y + _16))) {
				if ((x > _48 && x < _48 + _16)) {
					// 中间
					return actionMouse(KEY_NUM8, 0);
				} else if (x > (_48 - _32) && x < (_48 - _16)) {
					// 左
					return actionMouse(KEY_NUM4, 0);
				} else if (x > (_48 + _32) && x < _48 + _48) {
					// 右
					return actionMouse(KEY_NUM6, 0);
				}
			}

			// 移动精度滑条
			int py = sp_mouse_splide.getY();
			if (y > py && y < (py + sp_mouse_splide.getHeight())) {
				if (x > (_48 - _32) && x < (_48 + _48)) {
					if (x > (sp_mouse_splide.getX() + sp_mouse_splide
							.getWidth() / 2)) {
						// 在滑条右侧
						return actionMouse(KEY_NUM9, 0);
					} else {
						return actionMouse(KEY_NUM7, 0);
					}
				}
			}
			
			//点击[Esc:0]
			final short pointOnEsc = pointOnEsc(x, y, sp_tr_Mouse);
			if(pointOnEsc != R_CONTINUE){
				return pointOnEsc;
			}

		}

		short _out = (short)clickTouchMenu(x, y, false);
		if (_out >= 0) {
			return (short)((_out==0)?0:1);
		}

		sp_mouseMove_cursor.setPosition(x, y);
		if(isMouseRightClickOn){
			sendOutMouse(DataInputEvent.TYPE_MOUSE_RIGHT_CLICK);
		}else if(isMouseMoveOn){
			moveMouse(x, y);
		}else{
			sendOutMouse(DataInputEvent.TYPE_MOUSE_LEFT_CLICK);
		}
		return 1;
	}

	private short pointOnEsc(int x, int y, Sprite sp_l_panel) {
		//点击[ESC:0]
//		L.V = L.O ? false : LogManager.log("x : " + x + ", y : " + y);
//		L.V = L.O ? false : LogManager.log("panel, y : " + sp_l_panel.getY() + ", x : " + sp_l_panel.getX());
//		L.V = L.O ? false : LogManager.log("panel, w : " + sp_l_panel.getWidth());
		
		if(y > (sp_l_panel.getY()) && y < (sp_l_panel.getY() + ImageUtility.sp_bound 
				+ ImageUtility.UI_Font.getHeight())){
			if(x < sp_l_panel.getWidth()){
				int w_l_x1 = sp_l_panel.getWidth() - str_esc_strWidth - ImageUtility.sp_bound;
				if(x > w_l_x1){
//					L.V = L.O ? false : LogManager.log("focus on Esc");
					actionScreen(KEY_NUM0, 0);
					return R_OK;
				}
				//在面板内，但不在远屏区内，忽略本次点击
				return R_ERR;
			}
		}
		return R_CONTINUE;
	}
	
	private int clickTouchMenu(int x, int y, boolean isDouble) {
		if (x >= (userMouseWidthIdx) && x < (userMouseWidthIdx + _blockWidth)
				&& y >= userMouseHeightIdx) {
			int selectIdx = (y - userMouseHeightIdx) / _blockWidth;

			if (selectIdx < DataInputEvent.TYPE_START_USER_ICON) {
				userSelectedMenu.setVisible(true);
				userSelectedMenu.setPosition(userMouseWidthIdx + userMouseSplitWidth,
						userMouseHeightIdx + selectIdx * _blockWidth + userMouseSplitWidth);
				if (selectIdx == 0) {
					showTextUI(null);
				} else if (selectIdx == 1) {
					setModeTextSelectedBegin();
				} else if (selectIdx == 2) {
					if (isDouble) {
						backspace();
					}
					backspace();
				} else if (selectIdx == 3) {
					copyTxtToMobile();
				} else if (selectIdx == 4) {
					setModeMouseRightClickOn();
				} else if (selectIdx == 5) {
					setModeMouseMoveOn();
				}
				
				//因为idx=0时，应有回应声音，所以返回1
				return 1;
			}
		} else if (mouseOpUserListNum > 0) {
			// 含有用户扩展
			if (x >= (userMouseWidthIdx - _blockWidth) && x < userMouseWidthIdx
					&& y >= userMouseHeightIdx) {
				int selectIdx = (y - userMouseHeightIdx) / _blockWidth;
				if (selectIdx < mouseOpUserListNum) {
					userSelectedMenu.setVisible(true);
					userSelectedMenu.setPosition(userMouseWidthIdx - _blockWidth + userMouseSplitWidth,
							userMouseHeightIdx + selectIdx * _blockWidth + userMouseSplitWidth);

					if (isDouble) {
						sendOutMouse(selectIdx
								+ (DataInputEvent.TYPE_START_USER_ICON + 1));
					}
					sendOutMouse(selectIdx
							+ (DataInputEvent.TYPE_START_USER_ICON + 1));
					return 1;
				}else if(selectIdx >= mouseOpUserListNum && selectIdx < mouseOpUserLists.length){
//					System.out.println("Print Empty Item.");
					Starter.soundFail();
					return 0;
				}
			}
		}
		return -1;
	}

	private boolean isTextSelectedBegin = false;
	private boolean isMouseRightClickOn = false;
	private boolean isMouseMoveOn = false;

	public void setModeTextSelectedBegin(){
		if(isMouseRightClickOn){
			setModeMouseRightClickOn();
		}else if(isMouseMoveOn){
			setModeMouseMoveOn();
		}
		isTextSelectedBegin = !isTextSelectedBegin;
		
		flip(1);
	}

	public void setModeMouseRightClickOn(){
		if(isTextSelectedBegin){
			setModeTextSelectedBegin();
		}else if(isMouseMoveOn){
			setModeMouseMoveOn();
		}
		isMouseRightClickOn = !isMouseRightClickOn;
		flip(4);
	}
	
	public void setModeMouseMoveOn(){
		if(isTextSelectedBegin){
			setModeTextSelectedBegin();
		}else if(isMouseRightClickOn){
			setModeMouseRightClickOn();
		}
		isMouseMoveOn = !isMouseMoveOn;
		flip(5);
	}
	
	private void flip(int idx) {
		Sprite ms = mouseOpLists[idx];
		if(ms instanceof ModeSprite){
			((ModeSprite)ms).flip();
//			userSelectedMenu.setVisible();
		}
	}
	
	private void copyTxtToMobile() {
		sendOutMouse(DataInputEvent.TYPE_TAG_TRANS_TEXT_2_MOBI);
	}

	private void backspace() {
		sendOutMouse(DataInputEvent.TYPE_BACKSPACE);
	}

	/**
	 * 
	 * @param x
	 * @param y
	 * @return 如果需要响应成功音，则返回1；如果响应错误音，则返回-1；无音，则返回0
	 */
	private short actionPointDouble(final int x, final int y) {
//		L.V = L.O ? false : LogManager.log("Point double[" + x + ", " + y + "]");
		final short retclickTouchMenu = (short)clickTouchMenu(x, y, true);
		if (retclickTouchMenu >= 0) {
//			L.V = L.O ? false : LogManager.log("clickTouchMenu");
			return retclickTouchMenu;
		}

		// 小窗口方式下关闭双击功能
		if (curr_menu_mode == MODE_SCREEN) {
			int scr_y = sp_tr_Screen.getY();
			if (y > scr_y && y < (scr_y + sp_tr_Screen.getHeight()) && x > 0
					&& x < sp_tr_Screen.getWidth()) {
				return -1;
			}
		}
		if (curr_menu_mode == MODE_MOUSE) {
			int mus_y = sp_tr_Mouse.getY();
			if (y > mus_y && y < (mus_y + sp_tr_Mouse.getHeight()) && x > 0
					&& x < sp_tr_Mouse.getWidth()) {
				return -1;
			}
		}

		if(checkInMenu(x, y)){
			//不处理双击，强制作单击
//			L.V = L.O ? false : LogManager.log("Skip double click.");
			return actionPointSingClick(x, y);
		}
		
		sp_mouseMove_cursor.setPosition(x, y);
		sendOutMouse(DataInputEvent.TYPE_MOUSE_DOUBLE_CLICK);
		return 1;
	}

	private short actionMenu(int keyStates, int gameAction) {
		if (gameAction == LEFT || keyStates == KEY_NUM4) {
			if (indexSelectedMenuItem == 0) {
				return R_ERR;
			} else {
				userSelectedMenu.setPosition(_blockWidth
						* (--indexSelectedMenuItem) + userMouseSplitWidth, y_menu_item);
				return R_OK;
			}
		} else if (gameAction == RIGHT || keyStates == KEY_NUM6) {// (keyStates
																	// &
																	// RIGHT_PRESSED)
																	// != 0
			if (indexSelectedMenuItem < (visiable_icon_num - 1)) {
				userSelectedMenu.setPosition(_blockWidth
						* (++indexSelectedMenuItem) + userMouseSplitWidth, y_menu_item);
				return R_OK;
			} else {
				return R_ERR;
			}
		} else if (gameAction == UP || keyStates == KEY_NUM2) {
			if (indexSelectedMenuItem == ICON_MOUSE_IDX) {
				showMousePanel();
			} else if (indexSelectedMenuItem == ICON_ABOUT_IDX) {
				showAboutPanel();
			} else if (indexSelectedMenuItem == ICON_SCREEN_IDX) {
				showScreenPanel();
			} else {
				return R_ERR;
			}
			return R_OK;
		} else if (gameAction == DOWN || keyStates == KEY_NUM8) {
			return R_ERR;
		} else if (gameAction == FIRE || keyStates == KEY_NUM5) {
			if (indexSelectedMenuItem == ICON_EXIT_IDX) {
				responseActionSound(1, true);
				exit();
				return R_CANCEL;
			} else if (indexSelectedMenuItem == ICON_EXPAND_IDX) {
				if (visiable_icon_num == (indexSelectedMenuItem + 1)) {
					// 向右展开
					Image img = null;
					try {
						img = Image
								.createImage("/hc/j2me/res/leftarrow_" + _16 + ".png");
					} catch (IOException e) {
						e.printStackTrace();
					}
					sp_tb_services.setImage(img, _16, _16);

					sp_tb_mouse.setVisible(true);
					sp_tb_about.setVisible(true);
					sp_tb_screen.setVisible(true);
					sp_tb_config.setVisible(true);

					sp_tr_toolmenu.setPosition(0, y_menu);

					Starter.config.isHideToolbar = !Starter.config.isHideToolbar;
					Starter.update(Starter.config);

					visiable_icon_num += (TOTAL_MENU_ITEM_NUM - MENU_ITEM_NEVEN_HIDE_NUM);
				} else {
					// 向左收起
					Image img = null;
					try {
						img = Image
								.createImage("/hc/j2me/res/rightarrow_" + _16 + ".png");
					} catch (IOException e) {
						e.printStackTrace();
					}
					sp_tb_services.setImage(img, _16,
							_16);

					sp_tb_mouse.setVisible(false);
					sp_tb_about.setVisible(false);
					sp_tb_screen.setVisible(false);
					sp_tb_config.setVisible(false);

					visiable_icon_num -= (TOTAL_MENU_ITEM_NUM - MENU_ITEM_NEVEN_HIDE_NUM);

					sp_tr_toolmenu.setPosition(-TOTAL_MENU_ITEM_NUM
							* _blockWidth
							+ MENU_ITEM_NEVEN_HIDE_NUM
							* _blockWidth, y_menu);

					Starter.config.isHideToolbar = !Starter.config.isHideToolbar;
					Starter.update(Starter.config);
				}
				return R_OK;
			} else if (indexSelectedMenuItem == ICON_MOUSE_IDX) {
				showMousePanel();
			} else if (indexSelectedMenuItem == ICON_ABOUT_IDX) {
				showAboutPanel();
			} else if (indexSelectedMenuItem == ICON_SCREEN_IDX) {
				showScreenPanel();
			} else if (indexSelectedMenuItem == ICON_CFG_IDX) {
				showCfgPanel();
			} else {
				return R_ERR;
			}
			return R_OK;
		}
		return R_CANCEL;
	}

	private void showCfgPanel() {
		ConfigForm.showConfigForm();
	}

	private short str_esc_strWidth = 0;
	private int swidth, sheight;
	
	private void showScreenPanel() {
		curr_menu_mode = MODE_SCREEN;

		if (sp_tr_Screen == null) {
			swidth = ScreenClientManager.getClientWidth();
			sheight = ScreenClientManager.getClientHeight();

			int p_w, p_h;
//			final int MAX_SCREEN_SIZE = (sheight>swidth?swidth:sheight);
			if (sheight > swidth) {
				// 直屏机器
//				sheight = (swidth>MAX_SCREEN_SIZE?(MAX_SCREEN_SIZE*sheight/swidth):sheight);
//				swidth = (swidth>MAX_SCREEN_SIZE?MAX_SCREEN_SIZE:swidth);
				// 仿真显区宽
				p_w = swidth - 2 * ImageUtility.sp_bound;
				// 仿真显区高
				p_h = ScreenClientManager.remote_screen_height * p_w
						/ ScreenClientManager.remote_screen_width;
			} else {
				// 横屏机器
//				swidth = (sheight>MAX_SCREEN_SIZE?(MAX_SCREEN_SIZE*swidth/sheight):swidth);
//				sheight = (sheight>MAX_SCREEN_SIZE?MAX_SCREEN_SIZE:sheight);
				
				// 仿真显区宽
				p_h = sheight - 2 * ImageUtility.sp_bound
						- _blockWidth - ImageUtility.FontHeight;//
				// 仿真显区高
				p_w = ScreenClientManager.remote_screen_width * p_h
						/ ScreenClientManager.remote_screen_height;
			}
			sp_screen_focus = new Sprite(createSelectedBox(
					(p_w * ScreenClientManager.getClientWidth()) / ScreenClientManager.remote_screen_width,
					(p_h * ScreenClientManager.getClientHeight()) / ScreenClientManager.remote_screen_height,
					ImageUtility.GREEN));

			// 修正屏幕累计误差，以绘制实际可用仿真框
			int diffPH = p_h
					- (ScreenClientManager.getMobilePosY(
							ScreenClientManager.remote_screen_height - ScreenClientManager.getClientHeight(),
							p_h) + sp_screen_focus.getHeight());
			int diffPW = p_w
					- (ScreenClientManager.getMobilePosX(
							ScreenClientManager.remote_screen_width - ScreenClientManager.getClientWidth(),
							p_w) + sp_screen_focus.getWidth());
			
			// 实际全Panel高
			int total_h = p_h + ImageUtility.sp_bound * 2
					+ ImageUtility.FontHeight;
			int total_w = p_w + ImageUtility.sp_bound * 2 + diffPW;
			// 修正与仿真选择框的误差
			int x = 0, y = ScreenClientManager.getClientHeight() - total_h - _blockWidth;

			Image img = Image.createImage(total_w, total_h);// swidth
			Graphics g = img.getGraphics();
			final boolean alphaEnable = ImageUtility.isAlphaEnable();
			g.setColor(ImageUtility.COLOR_TRANS_LAY);
			g.fillRect(0, 0, total_w, total_h);

			drawBox(total_w, total_h, g);
			
			drawBox(ImageUtility.sp_bound - 1, ImageUtility.sp_bound
					+ ImageUtility.FontHeight - 1, p_w - diffPW + 2, p_h - diffPH + 2,
					g, 0x4aefef, 0x3a4152);

			g.setColor(0x4aefef);
			//左上角
			final int _gap = 6;
			drawCorner(g, ImageUtility.sp_bound + _gap, ImageUtility.sp_bound + ImageUtility.FontHeight + _gap, 5, 5);
			//右上角
			drawCorner(g, ImageUtility.sp_bound + p_w - diffPW - _gap, ImageUtility.sp_bound + ImageUtility.FontHeight + _gap, -5, 5);
			//左下角
			drawCorner(g, ImageUtility.sp_bound + _gap, ImageUtility.sp_bound + ImageUtility.FontHeight + p_h - diffPH - _gap, 5, -5);
			//右下角
			drawCorner(g, ImageUtility.sp_bound + p_w - diffPW - _gap, ImageUtility.sp_bound + ImageUtility.FontHeight + p_h - diffPH - _gap, -5, -5);
			
			g.setFont(ImageUtility.UI_Font);
			ImageUtility.setColor(g, ImageUtility.YELLOW);
			final String str_esc = "[0:Esc,X]";
			str_esc_strWidth = (short)ImageUtility.UI_Font.stringWidth(str_esc);
			g.drawString(str_esc, total_w - ImageUtility.sp_bound
					- str_esc_strWidth, // swidth
					ImageUtility.sp_bound - 2, 0);//-2 是某些环境下，字体会叠在下框上，所以-2上移
			if(alphaEnable){
				img = ImageUtility.tranBlackToTransfor(img, false);
			}
			sp_tr_Screen = new Sprite(img);
			sp_tr_Screen.setPosition(0, y);
			V_X = ImageUtility.sp_bound;
			
			//原为_16改为FontHeight
//			V_Y = y + ImageUtility.sp_bound + _16;
			V_Y = y + ImageUtility.sp_bound + ImageUtility.FontHeight;
			
//			lm.insert(sp_tr_Screen, LI_TRANS);

			Virtual_W = p_w;
			Virtual_H = p_h;
			// ScreenClientManager.getClientHeight() - _16 - sp_bound -
			// sp_screen_focus.getHeight()
//			lm.insert(sp_screen_focus, LI_TOOLMENU);//LI_SELECTED
			
			Object[] sps = {sp_tr_Screen, sp_screen_focus};
			SpritesLoc spLoc = new SpritesLoc(sps, LOCK, this);
			spLoc.isMoveIn = false;
			spLoc.moveY = total_h + _blockWidth;
		
			screenMover = new SpriteMover();
			screenMover.spriteloc = spLoc;

			sp_tr_Screen.setVisible(false);
			sp_screen_focus.setVisible(false);
			
			final int toolMenuIdx = PNGGameCanvas.getLayerIdx(lm, sp_tr_toolmenu) + 1;
			lm.insert(sp_tr_Screen, toolMenuIdx);//LI_SELECTED
			lm.insert(sp_screen_focus, toolMenuIdx);//LI_SELECTED
		} else {
//			sp_tr_Screen.setVisible(true);
//			sp_screen_focus.setVisible(true);
		}
		if(screenMover.isAddWatch() == false){
			refreshScreenFocus();
	
			screenMover.flipMove();
		}
	}

	private void refreshScreenFocus() {
		virtualMoveLocX = locX;
		virtualMoveLocY = locY;

		sp_screen_focus.setPosition(
				V_X
						+ ScreenClientManager.getMobilePosX(virtualMoveLocX,
								Virtual_W),
				V_Y
						+ ScreenClientManager.getMobilePosY(virtualMoveLocY,
								Virtual_H));
	}
	
	private void drawCorner(Graphics g, int x, int y, int dirX, int dirY) {
		g.drawLine(x, y, x + dirX, y);
//		g.drawLine(x, y + ((dirY > 0)?1:-1), x + dirX + ((dirX > 0)?-1:1), y + ((dirY > 0)?1:-1));
		
		g.drawLine(x, y, x, y + dirY);
//		g.drawLine(x + ((dirX > 0)?1:-1), y, x + ((dirX > 0)?1:-1), y + dirY + ((dirY > 0)?-1:1));
	}

	private void drawBox(final int width, final int height, final Graphics g) {
		//画最外边框
//		g.setColor(upSideColor);
//		g.drawLine(0, 0, width, 0);
//		g.drawLine(0, 0, 0, height);
//		g.setColor(downSideColor);
//		final int width_1 = width - 1;
//		g.drawLine(width_1, 0, width_1, height);
//		final int height_1 = height - 1;
//		g.drawLine(0, height_1, width_1, height_1);
		
		drawrect(0, 0, width-1, height-1, g, ImageUtility.downSideColor);
		drawrect(1, 1, width-2, height-2, g, ImageUtility.upSideColor);
		
//		g.setColor(upSideColor);//0xaa8d60
//		g.drawLine(1, 1, width-2, 1);
//		g.drawLine(1, 1, 1, height-2);
//		g.drawLine(width-2, 1, width-2, height-2);
//		g.drawLine(1, height-2, width-2, height-2);
		
	}

	private void drawrect(final int x, int y, final int x2, final int y2, final Graphics g, int color) {
		g.setColor(color);
		g.drawLine(x, y, x2, y);
		g.drawLine(x, y, x, y2);
		g.drawLine(x2, y, x2, y2);
		g.drawLine(x, y2, x2, y2);
	}

	private void drawBox(final int x, final int y, final int width, final int height, 
			final Graphics g, final int upColor, final int downColor) {
		
		//上左阴
		g.setColor(downColor);
		g.drawLine(x + 1, y + 1, x + width, y + 1);
		g.drawLine(x + 1, y + 1, x + 1, y + height - 1);
		//上左阳
		g.setColor(upColor);
		g.drawLine(x, y, x + width - 1, y);
		g.drawLine(x, y, x, y + height - 1);
		
		//右下阳
		g.setColor(upColor);
		final int width_1 = width - 1;
		g.drawLine(x + width_1, y + 1, x + width_1, y + height);
		final int height_1 = height - 1;
		g.drawLine(x + 1, y + height_1, x + width_1, y + height_1);
		
		//右下阴
		g.setColor(downColor);
		g.drawLine(x + width_1 + 1, y + 1, x + width_1 + 1, y + height);
		g.drawLine(x + 1, y + height_1 + 1, x + width_1, y + height_1 + 1);
	}

	private void showAboutPanel() {
//		System.out.println("UI Font height:" + ImageUtility.UI_Font.getHeight());
		curr_menu_mode = MODE_ABOUT;
		int aboutWidth = ScreenClientManager.getClientWidth() - 2
				* ImageUtility.sp_bound;
		if(aboutWidth > 240){
			aboutWidth = 240;
		}
		Image img = Image.createImage(aboutWidth, 70 + ImageUtility.UI_Font.getHeight() * 3);
		Graphics g = img.getGraphics();
		final boolean alphaEnable = ImageUtility.isAlphaEnable();
		g.setColor(ImageUtility.COLOR_TRANS_LAY);
		g.fillRect(0, 0, img.getWidth(), img.getHeight());

		drawBox(img.getWidth(), img.getHeight(), g);
		
		g.setFont(ImageUtility.UI_Font);
		ImageUtility.setColor(g, ImageUtility.WHITE);
		g.drawString("HomeCenter V" + Main.getMidletVer(), img.getWidth() / 2, 12, 
				Graphics.TOP | Graphics.HCENTER);

		g.drawString("Dev by HomeCenter.MOBI", img.getWidth() / 2, 16 + ImageUtility.UI_Font.getHeight(),
				Graphics.TOP | Graphics.HCENTER);
		g.drawString("All Rights Reserved", img.getWidth() / 2, 71 + ImageUtility.UI_Font.getHeight(),
				Graphics.TOP | Graphics.HCENTER);

		if(alphaEnable){
			img = ImageUtility.tranBlackToTransfor(img, false);
		}
		sp_tr_About = new Sprite(img);
		sp_tr_About.setPosition((ScreenClientManager.getClientWidth() - aboutWidth)/2,
				(ScreenClientManager.getClientHeight() - img.getHeight()) / 2);		
		lm.insert(sp_tr_About, 0);
		
		try {
			sp_tr_About_logo = new Sprite(Image.createImage("/hc/j2me/res/hc_32.png"));
			sp_tr_About_logo.setPosition(sp_tr_About.getX() + sp_tr_About.getWidth() / 2 - sp_tr_About_logo.getWidth() / 2, 
					sp_tr_About.getY() + 37 + ImageUtility.UI_Font.getHeight());
			
			lm.insert(sp_tr_About_logo, 0);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private void closeScreenPanel() {
//		sp_tr_Screen.setVisible(false);
//		sp_screen_focus.setVisible(false);
		
		screenMover.flipMove();
		
		curr_menu_mode = MODE_MENU;
	}

	private void closeAboutPanel() {
		lm.remove(sp_tr_About);
		lm.remove(sp_tr_About_logo);
		sp_tr_About = null;
		sp_tr_About_logo = null;
		curr_menu_mode = MODE_MENU;
	}

	private void closeMousePanel() {
//		sp_tr_Mouse.setVisible(false);
//		sp_mouse_focus.setVisible(false);
//		sp_mouse_splide.setVisible(false);
		mouseMover.flipMove();
		curr_menu_mode = MODE_MENU;
	}
	
	public void exit() {
		
		//保留为以后使用的接口和逻辑
//		MsgNotifier.getInstance().popCurrListener();
		
		posMVC = null;
		screenMover = null;
		mouseMover = null;
		userOpMover = null;
		
		ContextManager.getContextInstance().send(MsgBuilder.E_GOTO_URL,
				HCURL.URL_CMD_EXIT);
		
		super.exit();
		
		//由于HCCtrlGameCanvas不同于ActionCanvas，需要自行退出，所以本处要增加exitOrReturn
		UIManager.exitOrReturn();
	}

	private void showMousePanel() {
		curr_menu_mode = MODE_MOUSE;

		if (sp_tr_Mouse == null) {
			String str_esc = "Esc:[0]";
			String str_abc = "ab:[*]";
			String str_1 = "[1]";
			String str_4 = "[4]";
			String str_7 = "[7]";
			if (ImageUtility.UI_Font.stringWidth(str_1) > _16) {
				str_esc = "Esc[0]";
				str_abc = "ab[*]";
				str_1 = "1]";
				str_4 = "4]";
				str_7 = "7]";
			}
			int p_w = _16 * 6, p_h = _16 * 2 + ImageUtility.sp_bound
					+ ImageUtility.FontHeight + _16 + 2;

			// 修正与仿真选择框的误差
			int x = 0, y = ScreenClientManager.getClientHeight() - p_h - _blockWidth;

			Image img = Image.createImage(p_w, p_h);// swidth
			Graphics g = img.getGraphics();
			final boolean alphaEnable = ImageUtility.isAlphaEnable();
			g.setColor(ImageUtility.COLOR_TRANS_LAY);
			g.fillRect(0, 0, p_w, p_h);// swidth

			drawBox(p_w, p_h, g);
			
			g.setFont(ImageUtility.UI_Font);
			ImageUtility.setColor(g, ImageUtility.YELLOW);
			g.drawString(str_esc,
					p_w - ImageUtility.UI_Font.stringWidth(str_esc), // swidth
					ImageUtility.sp_bound - 2, 0);

			g.drawString(str_abc, 0, ImageUtility.sp_bound - 2, 0);

			int splide_line_y = p_h - 5;
			final int _96 = _16 * 6;
			{
				final int _splide_len = _96-3;//-3是顶出边界了
				g.setColor(157, 156, 153);
				g.drawLine(_16, splide_line_y - 1, _splide_len, splide_line_y - 1);

				g.setColor(242, 241, 233);
				g.drawLine(_16, splide_line_y, _splide_len, splide_line_y);
				g.drawLine(_16, splide_line_y + 1, _splide_len, splide_line_y + 1);
			}
			
			ImageUtility.setColor(g, ImageUtility.YELLOW);
			g.drawChar('1', _16, splide_line_y - 1 - ImageUtility.FontHeight, 0);
			g.drawChar('5', _32, splide_line_y - 1 - ImageUtility.FontHeight, 0);
			g.drawString("10", _48, splide_line_y - 1 - ImageUtility.FontHeight, 0);
			final int _66 = 2 + _16 * 4;
			g.drawString("20", _66, splide_line_y - 1 - ImageUtility.FontHeight,
					Graphics.TOP | Graphics.LEFT);
			g.drawString("40", _96, splide_line_y - 1 - ImageUtility.FontHeight,
					Graphics.TOP | Graphics.RIGHT);

			// 绘制鼠标各图标
			try {
				M_SECOND_ICON_Y = p_h - _16 - _16 - 4;
				g.drawImage(Image.createImage("/hc/j2me/res/leftarrow_" + _16 + ".png"),
						_16, M_SECOND_ICON_Y, 0);
				g.drawImage(Image.createImage("/hc/j2me/res/downarrow_" + _16 + ".png"),
						_48, M_SECOND_ICON_Y, 0);
				g.drawImage(
						Image.createImage("/hc/j2me/res/rightarrow_" + _16 + ".png"),
						_80, M_SECOND_ICON_Y, 0);

				M_FIRST_ICON_Y = p_h - _32 - _16 - 4;
				g.drawImage(Image.createImage("/hc/j2me/res/mus_lft_" + _16 + ".png"),
						_16, M_FIRST_ICON_Y, 0);
				g.drawImage(Image.createImage("/hc/j2me/res/uparrow_" + _16 + ".png"),
						_48, M_FIRST_ICON_Y, 0);
				g.drawImage(Image.createImage("/hc/j2me/res/mus_rit_" + _16 + ".png"),
						_80, M_FIRST_ICON_Y, 0);
			} catch (Exception e) {

			}

			// 绘制提示按钮数字键
			g.drawString(str_1, 0, M_FIRST_ICON_Y
					+ ((_16 - ImageUtility.FontHeight) / 2), 0);
			g.drawString(str_4, 0, M_SECOND_ICON_Y
					+ ((_16 - ImageUtility.FontHeight) / 2), 0);
			g.drawString(str_7, 0, splide_line_y + 5 - ImageUtility.FontHeight, 0);

			if(alphaEnable){
				img = ImageUtility.tranBlackToTransfor(img, false);
			}
			sp_tr_Mouse = new Sprite(img);
			sp_tr_Mouse.setPosition(0, y);
			M_X = 0;
			M_Y = y;
			sp_tr_Mouse.setVisible(false);
			final int toolMenuIdx = PNGGameCanvas.getLayerIdx(lm, sp_tr_toolmenu) + 1;
			lm.insert(sp_tr_Mouse, toolMenuIdx);

			sp_mouse_focus = new Sprite(createSelectedBox(_16, _16,
					ImageUtility.GREEN));

			// ScreenClientManager.getClientHeight() - _16 - sp_bound -
			// sp_screen_focus.getHeight()
			sp_mouse_focus.setVisible(false);
			lm.insert(sp_mouse_focus, toolMenuIdx);

			try {
				//鼠标仿真状态下的像素移到尺度 游标
				sp_mouse_splide = new Sprite(
						Image.createImage("/hc/j2me/res/splide.png"));
			} catch (IOException e) {
				e.printStackTrace();
			}
			sp_mouse_splide.setPosition(_48, M_Y + p_h - 10);
			sp_mouse_splide.setVisible(false);
			lm.insert(sp_mouse_splide, toolMenuIdx);
			
			Sprite[] sps = {sp_tr_Mouse, sp_mouse_focus, sp_mouse_splide};
			SpritesLoc spLoc = new SpritesLoc(sps, LOCK, this);
			spLoc.isMoveIn = false;
			spLoc.moveY = p_h + _blockWidth;
		
			mouseMover = new SpriteMover();
			mouseMover.spriteloc = spLoc;

		} else {
//			sp_tr_Mouse.setVisible(true);
//			sp_mouse_focus.setVisible(true);
//			sp_mouse_splide.setVisible(true);
		}
		if(mouseMover.isAddWatch() == false){
			sp_mouse_focus.setPosition(_48, M_Y + M_FIRST_ICON_Y);
			
			mouseMover.flipMove();
		}
	}

	private final int MOUSE_MOVE_BOUND = 20;

	private short actionMouse(int keyStates, int gameAction) {
		if (gameAction == LEFT || keyStates == KEY_NUM4) {
			if (sp_mouse_focus.getX() == _16
					&& sp_mouse_focus.getY() == M_Y + M_SECOND_ICON_Y) {
			} else {
				sp_mouse_focus.setPosition(_16, M_Y + M_SECOND_ICON_Y);
			}

			int mm_x = sp_mouseMove_cursor.getX() - pixel_num_mouse_move;
			if (mm_x < MOUSE_MOVE_BOUND) {
				int diff = MOUSE_MOVE_BOUND - mm_x;

				int rm = ScreenClientManager.checkMoveRight(
						locX, -diff);
				if (rm == 0) {
					if (mm_x < 0) {
						// 外边也不能移
						return R_ERR;
					} else {
						moveMouse(mm_x, sp_mouseMove_cursor.getY());
						return R_OK;
					}
				}
				ScreenClientManager.moveRight(rm);

				// 其余部分
				moveMouse(sp_mouseMove_cursor.getX()
						- (pixel_num_mouse_move + rm),
						sp_mouseMove_cursor.getY());
				return R_OK;
			} else {
				moveMouse(mm_x, sp_mouseMove_cursor.getY());
				return R_OK;
			}
		} else if (gameAction == RIGHT || keyStates == KEY_NUM6) {
			if (sp_mouse_focus.getX() == _80
					&& sp_mouse_focus.getY() == M_Y + M_SECOND_ICON_Y) {
			} else {
				sp_mouse_focus.setPosition(_80, M_Y + M_SECOND_ICON_Y);
			}

			int mm_x = sp_mouseMove_cursor.getX() + pixel_num_mouse_move;
			if (mm_x > (ScreenClientManager.getClientWidth() - MOUSE_MOVE_BOUND)) {
				int diff = mm_x - (ScreenClientManager.getClientWidth() - MOUSE_MOVE_BOUND);

				int rm = ScreenClientManager.checkMoveRight(
						locX, diff);
				if (rm == 0) {
					if (mm_x > ScreenClientManager.getClientWidth()) {
						// 外边也不能移
						return R_ERR;
					} else {
						moveMouse(mm_x, sp_mouseMove_cursor.getY());
						return R_OK;
					}
				}
				ScreenClientManager.moveRight(rm);

				// 其余部分
				moveMouse(sp_mouseMove_cursor.getX()
						+ (pixel_num_mouse_move - rm),
						sp_mouseMove_cursor.getY());
				return R_OK;
			} else {
				moveMouse(mm_x, sp_mouseMove_cursor.getY());
				return R_OK;
			}

		} else if (gameAction == UP || keyStates == KEY_NUM2) {
			if (sp_mouse_focus.getX() == _48
					&& sp_mouse_focus.getY() == M_Y + M_FIRST_ICON_Y) {
			} else {
				sp_mouse_focus.setPosition(_48, M_Y + M_FIRST_ICON_Y);
			}

			int mm_x = sp_mouseMove_cursor.getY() - pixel_num_mouse_move;
			if (mm_x < MOUSE_MOVE_BOUND) {
				int diff = MOUSE_MOVE_BOUND - mm_x;

				int rm = ScreenClientManager.checkMoveUp(
						locY, diff);
				if (rm == 0) {
					if (mm_x < 0) {
						// 外边也不能移
						return R_ERR;
					} else {
						moveMouse(sp_mouseMove_cursor.getX(), mm_x);
						return R_OK;
					}
				}
				ScreenClientManager.moveUp(rm);

				// 其余部分
				moveMouse(sp_mouseMove_cursor.getX(),
						sp_mouseMove_cursor.getY()
								- (pixel_num_mouse_move - rm));
				return R_OK;
			} else {
				moveMouse(sp_mouseMove_cursor.getX(), mm_x);
				return R_OK;
			}
		} else if (gameAction == DOWN || keyStates == KEY_NUM8) {
			if (sp_mouse_focus.getX() == _48
					&& sp_mouse_focus.getY() == M_Y + M_SECOND_ICON_Y) {
			} else {
				sp_mouse_focus.setPosition(_48, M_Y + M_SECOND_ICON_Y);
			}

			int mm_x = sp_mouseMove_cursor.getY() + pixel_num_mouse_move;
			if (mm_x > (ScreenClientManager.getClientHeight() - MOUSE_MOVE_BOUND)) {
				int diff = mm_x - (ScreenClientManager.getClientHeight() - MOUSE_MOVE_BOUND);

				int rm = ScreenClientManager.checkMoveUp(
						locY, -diff);
				if (rm == 0) {
					if (mm_x > ScreenClientManager.getClientHeight()) {
						// 外边也不能移
						return R_ERR;
					} else {
						moveMouse(sp_mouseMove_cursor.getX(), mm_x);
						return R_OK;
					}
				}
				ScreenClientManager.moveUp(rm);

				// 其余部分
				moveMouse(sp_mouseMove_cursor.getX(),
						sp_mouseMove_cursor.getY()
								+ (pixel_num_mouse_move + rm));
				return R_OK;
			} else {
				moveMouse(sp_mouseMove_cursor.getX(), mm_x);
				return R_OK;
			}
		} else if (gameAction == FIRE || keyStates == KEY_NUM5) {
			// 双击
			sendOutMouse(DataInputEvent.TYPE_MOUSE_DOUBLE_CLICK);
		} else if (keyStates == KEY_NUM1 || keyStates == KEY_NUM1_NO_STANDARD 
				|| keyStates == LEFT_SOFT_KEY) {
			// 单击左键
			sendOutMouse(DataInputEvent.TYPE_MOUSE_LEFT_CLICK);
		} else if (keyStates == KEY_NUM3 || keyStates == KEY_NUM3_NO_STANDARD 
				|| keyStates == RIGHT_SOFT_KEY) {
			// 鼠标右键
			sendOutMouse(DataInputEvent.TYPE_MOUSE_RIGHT_CLICK);
		} else if (keyStates == KEY_NUM7 || keyStates == KEY_NUM7_NO_STANDARD) {
			// 调小移距
			int x = sp_mouse_splide.getX();
			if (x == (_16 - 4)) {
				return R_ERR;
			} else if (x == _83) {
				sp_mouse_splide.setPosition(_64, sp_mouse_splide.getY());
				pixel_num_mouse_move = 20;
			} else if (x == _64) {
				sp_mouse_splide.setPosition(_48, sp_mouse_splide.getY());
				pixel_num_mouse_move = 10;
			} else if (x == _48) {
				sp_mouse_splide.setPosition(x - _16 - 4, sp_mouse_splide.getY());
				pixel_num_mouse_move = 5;
			} else {
				sp_mouse_splide.setPosition(x - _16, sp_mouse_splide.getY());
				pixel_num_mouse_move = 1;
			}
			return R_OK;
		} else if (keyStates == KEY_NUM9 || keyStates == KEY_NUM9_NO_STANDARD) {
			// 调大移距
			int x = sp_mouse_splide.getX();
			if (x == _83) {
				return R_ERR;
			} else if (x == _64) {
				sp_mouse_splide.setPosition(_83, sp_mouse_splide.getY());
				pixel_num_mouse_move = 40;
			} else if (x == _48) {
				sp_mouse_splide.setPosition(_64, sp_mouse_splide.getY());
				pixel_num_mouse_move = 20;
			} else if (x == (_32 - 4)) {
				sp_mouse_splide.setPosition(_48, sp_mouse_splide.getY());
				pixel_num_mouse_move = 10;
			} else {
				sp_mouse_splide.setPosition(x + _16, sp_mouse_splide.getY());
				pixel_num_mouse_move = 5;
			}
			return R_OK;
		} else if (keyStates == KEY_POUND) {
			// 进入backspace
			backspace();
		} else if (keyStates == KEY_STAR) {
			showTextUI(null);
		} else if (keyStates == KEY_NUM0 || keyStates == C_BACK_SOFT_KEY
				|| keyStates == KEY_NUM0_NO_STANDARD) {// 右侧Ｃ键，属于彩蛋型按钮
			// 关闭MousePanel
			closeMousePanel();
			return R_OK;
		}
		return R_CANCEL;
	}


	public void sendOutMouse(int mouseEventType) {
		DataInputEvent e = new DataInputEvent();
		final byte[] outMouseBS = new byte[MsgBuilder.UDP_BYTE_SIZE];
		
		e.setBytes(outMouseBS);

		e.resetText();
		e.setType(mouseEventType);
		e.setX(locX + sp_mouseMove_cursor.getX());
		e.setY(locY + sp_mouseMove_cursor.getY());
		ContextManager.getContextInstance().send(MsgBuilder.E_INPUT_EVENT, outMouseBS,
				e.getLength());
	}

	/**
	 * 本屏绝对坐标
	 * 
	 * @param x
	 * @param y
	 */
	private void moveMouse(int x, int y) {
		DataInputEvent e = new DataInputEvent();
		final byte[] mmBS = new byte[MsgBuilder.UDP_BYTE_SIZE];
		
		e.setBytes(mmBS);

		e.resetText();
		e.setType(DataInputEvent.TYPE_MOUSE_MOVE);
		e.setX(locX + x);
		e.setY(locY + y);
		ContextManager.getContextInstance().send(MsgBuilder.E_INPUT_EVENT, mmBS, e.getLength());

		sp_mouseMove_cursor.setPosition(x, y);
	}

	private short actionAbout(int keyStates, int gameAction) {
		// 关闭KeyPanel
		closeAboutPanel();
		return 1;
	}

	// 仿真全屏显示远程机器的左顶角，对应于真实屏的坐标
	private int virtualMoveLocX, virtualMoveLocY;

	private int pixel_num_mouse_move = 10;

	// 仿真屏的初始坐标
	private int V_X, V_Y, M_X, M_Y, M_SECOND_ICON_Y, M_FIRST_ICON_Y;

	// 仿真屏的相素宽高
	private int Virtual_W, Virtual_H;

	private short actionScreen(int keyStates, int gameAction) {
		if (gameAction == LEFT || keyStates == KEY_NUM4) {
			int moveDiff = ScreenClientManager.checkMoveRight(virtualMoveLocX,
					-swidth);
			if (moveDiff == 0) {
				return -1;
			}
			virtualMoveLocX += moveDiff;
			sp_screen_focus.setPosition(
					ImageUtility.sp_bound
							+ ScreenClientManager.getMobilePosX(
									virtualMoveLocX, Virtual_W),
					V_Y
							+ ScreenClientManager.getMobilePosY(
									virtualMoveLocY, Virtual_H));
			return 1;
		} else if (gameAction == RIGHT || keyStates == KEY_NUM6) {
			int moveDiff = ScreenClientManager.checkMoveRight(virtualMoveLocX,
					+swidth);
			if (moveDiff == 0) {
				return -1;
			}
			virtualMoveLocX += moveDiff;
			sp_screen_focus.setPosition(
					ImageUtility.sp_bound
							+ ScreenClientManager.getMobilePosX(
									virtualMoveLocX, Virtual_W),
					V_Y
							+ ScreenClientManager.getMobilePosY(
									virtualMoveLocY, Virtual_H));
			return 1;
		} else if (gameAction == UP || keyStates == KEY_NUM2) {
			int moveDiff = ScreenClientManager.checkMoveUp(virtualMoveLocY,
					+sheight);
			if (moveDiff == 0) {
				return -1;
			}
			virtualMoveLocY -= moveDiff;
			sp_screen_focus.setPosition(
					ImageUtility.sp_bound
							+ ScreenClientManager.getMobilePosX(
									virtualMoveLocX, Virtual_W),
					V_Y
							+ ScreenClientManager.getMobilePosY(
									virtualMoveLocY, Virtual_H));
			return 1;
		} else if (gameAction == DOWN || keyStates == KEY_NUM8) {
			int moveDiff = ScreenClientManager.checkMoveUp(virtualMoveLocY,
					-sheight);
			if (moveDiff == 0) {
				return -1;
			}
			virtualMoveLocY -= moveDiff;
			sp_screen_focus.setPosition(
					ImageUtility.sp_bound
							+ ScreenClientManager.getMobilePosX(
									virtualMoveLocX, Virtual_W),
					V_Y
							+ ScreenClientManager.getMobilePosY(
									virtualMoveLocY, Virtual_H));
			return 1;
		} else if (gameAction == FIRE || keyStates == KEY_NUM5) {
			if (virtualMoveLocX == locX
					&& virtualMoveLocY == locY) {
				// 用户又移回原点呢
				return -1;
			}
			ScreenClientManager.refreshRect(virtualMoveLocX, virtualMoveLocY);
			virtualMoveLocX = locX;
			virtualMoveLocY = locY;
			return 1;
		} else if (keyStates == KEY_NUM0 || keyStates == KEY_NUM0_NO_STANDARD
				|| keyStates == RIGHT_SOFT_KEY
				|| keyStates == KEY_NUM3 || keyStates == KEY_NUM3_NO_STANDARD) {// 后两个属于彩蛋型按钮
			if(curr_menu_mode == MODE_SCREEN){
				closeScreenPanel();
			}else if(curr_menu_mode == MODE_MOUSE){
				closeMousePanel();
			}
			return 1;
		}
		return 0;
	}

	
	public static final int KEY_NUM0_NO_STANDARD = 63575;
	public static final int KEY_NUM1_NO_STANDARD = 63490;
	public static final int KEY_NUM3_NO_STANDARD = 63492;
	public static final int KEY_NUM7_NO_STANDARD = 63491;
	public static final int KEY_NUM9_NO_STANDARD = 63493;
	
	public int getClientHeight() {
		return ScreenClientManager.getClientHeight();
	}

	public int getClientWidth() {
		return ScreenClientManager.getClientWidth();
	}

	public final void drawImage(final int x, final int y, final int w, final int h, final byte[] bs, final int offset,
			final int len) {
		
		screenGraph.drawImage(Image.createImage(bs, offset, len), x, y,
				Graphics.TOP | Graphics.LEFT);
		
//		dragStopDelayTimer.resetMode();
			
	}

	public void copyArea(int x, int y, int width, int height, int dx, int dy) {
		if (dx == 0) {
			if (dy >= 0) {
				screenGraph.copyArea(x, y, width, height, dx, dy, Graphics.TOP
						| Graphics.LEFT);
			} else {
				screenGraph.copyArea(x, y, width, height, dx, 0, Graphics.TOP
						| Graphics.LEFT);
			}
		}
		if (dy == 0) {
			if (dx <= 0) {
				screenGraph.copyArea(x, y, width, height, 0, dy, Graphics.TOP
						| Graphics.LEFT);
			} else {
				screenGraph.copyArea(x, y, width, height, dx, dy, Graphics.TOP
						| Graphics.LEFT);
			}
		}
	}

	public void fillRect(int x, int y, int width, int height) {
		screenGraph.fillRect(x, y, width, height);
	}

	public void setGrayToEmptyArea() {
		ImageUtility.setColor(screenGraph, ImageUtility.GRAY);
	}

	public void succMoveRight(int pixle) {
		// TODO Auto-generated method stub

	}

	public void succMoveUp(int pixle) {
		// TODO Auto-generated method stub

	}

	public void noMoveWarn() {
		// TODO Auto-generated method stub

	}

	private boolean enableMoveDown, enableMoveUp, enableMoveLeft,
			enableMoveRight;

	public void enableMoveDown(boolean e) {
		enableMoveDown = e;
	}

	public void enableMoveLeft(boolean e) {
		enableMoveLeft = e;
	}

	public void enableMoveRight(boolean e) {
		enableMoveRight = e;
	}

	public void enableMoveUp(boolean e) {
		enableMoveUp = e;
	}

	public void notifyRemoteSize(int width, int height) {
	}

	public void commandAction(Command c, Displayable disp) {
		if (disp == dispRemoteTxtBox) {
			if (c == Starter.cmd_ok) {
				UIManager.exitOrReturn();
			}
		}else{
			super.commandAction(c, disp);
		}
	}

	public void sendBackTxtToClient(String txt) {
		if (dispRemoteTxtBox == null) {
			dispRemoteTxtBox = new TextBox(Starter.getUIString("m09"), "",
					DataInputEvent.MAX_MOBI_UI_TXT_LEN, TextField.ANY);
			dispRemoteTxtBox.addCommand(Starter.cmd_ok);
			dispRemoteTxtBox.setCommandListener(this);
		}
		dispRemoteTxtBox.setString(txt);
		UIManager.pushInAndSwithToNew(dispRemoteTxtBox);
	}

	public static Image createSelectedBox(int w, int h, short color){
			final int[] imgData = new int[w * h];
			
			//保持相同的透明度alpha
			final int rgbColor = ImageUtility.getColor(color) | (0xFF000000);
			final int x1 = 0, y1 = 0;
			final int x2 = w - 1;
			final int y2 = h - 1;
			
			//顶
			ImageUtility.drawLine(x1, y1, x2 + 1, y1, rgbColor, imgData, w, false);
			//左
			ImageUtility.drawLine(x1, y1, x1, y2, rgbColor, imgData, w, false);
			//右
			ImageUtility.drawLine(x2, y1, x2, y2, rgbColor, imgData, w, false);
			//底
			ImageUtility.drawLine(x1, y2, x2 + 1, y2, rgbColor, imgData, w, false);

			return ImageUtility.createSafeAlphaImg(imgData, w, h, imgData.length, true);
		}

	public static void enterRemoteScreen(String hcurl) {
		ContextManager.getContextInstance().send(MsgBuilder.E_GOTO_URL, hcurl);

		// 由于本屏不可能再开启新子屏，所以不用考虑一个UI多处使用的情形。
		HCCtrlGameCanvas hcgame = new HCCtrlGameCanvas();
		UIManager.pushInAndSwithToNew(hcgame);
	}

	public void notifyNewMsg() {
	}

	public void setNextMsgListener(BackendMsgListener next) {
		this.next = next;
	}
	private BackendMsgListener next;
	public BackendMsgListener getNextMsgListener() {
		return next;
	}

}
